package vn.codespot.hms;

import java.util.ArrayList;
import java.util.List;

import vn.codespot.VisaVietNamAndroid.R;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class HistoryAdapter extends ArrayAdapter<String>{
	Context mContext;
	int mResourceId;
	ArrayList<String> mHistories;

	public HistoryAdapter(Context context, int textViewResourceId,
			List<String> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		this.mContext = context;
		this.mResourceId = textViewResourceId;
		this.mHistories = (ArrayList<String>) objects;
	}

	public static class ViewHolder {
		public TextView tv = null;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
	
		View v = convertView;
		ViewHolder viewholder;
		
		if (v == null) {
			LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = li.inflate(mResourceId, null);
			
			viewholder = new ViewHolder(); 	
			viewholder.tv = (TextView) v.findViewById(R.id.text);
			v.setTag(viewholder);
		} else {
			viewholder = (ViewHolder)v.getTag();
		}
		
		String str = mHistories.get(position);
		if (str != null && str != "") {
			viewholder.tv.setText(str);
		}
		
		return v;
	}
	
	
}
